package com.zjmzxfzhl.modules.app.service.impl;

import com.zjmzxfzhl.modules.app.entity.AppTaskTag;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjmzxfzhl.common.core.base.BaseServiceImpl;
import com.zjmzxfzhl.modules.app.entity.AppTempTag;
import com.zjmzxfzhl.modules.app.mapper.AppTempTagMapper;
import com.zjmzxfzhl.modules.app.service.AppTempTagService;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Service
 * 
 * @author 张森荣
 */
@Service
public class AppTempTagServiceImpl extends BaseServiceImpl<AppTempTagMapper, AppTempTag>
        implements AppTempTagService {
    @Override
    public IPage<AppTempTag> list(IPage<AppTempTag> page, AppTempTag appTempTag) {
        return page.setRecords(baseMapper.list(page, appTempTag));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveAppTempTag(AppTempTag appTempTag) {
        List<AppTempTag> appTempTagList=baseMapper.list(null, appTempTag);
        if(appTempTagList.size()>0){
            return false;
        }
        appTempTag.setId(UUID.randomUUID().toString().replace("-", "").toLowerCase());
        Boolean result=this.save(appTempTag);
        return result;
    }

    /**
     * 新增项目，自动计算机构级别、机构级次码、是否叶子
     *
     * @param appTempTag
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean relationDel(AppTempTag appTempTag) {
        Map<String, Object> columnMap=new HashMap<>();
        if (appTempTag.getTempId() == null && appTempTag.getTagId() == null) {
            return false;
        }
        if(appTempTag.getTempId()!=null){
            columnMap.put("TEMP_ID",appTempTag.getTempId());
        }
        if(appTempTag.getTagId()!=null){
            columnMap.put("TAG_ID",appTempTag.getTagId());
        }
        Boolean result=this.removeByMap(columnMap);
        return result;
    }
}
